package com.ruoyi.project.roadnet.baseMap.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.roadnet.baseRoadwaysection.domain.BaseRoadwaysection;
import com.ruoyi.project.roadnet.baseRoadwaysection.service.IBaseRoadwaysectionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 桥梁信息操作处理
 *
 * @author zhangdachen
 * @date 2019-04-16
 */
@Controller
@RequestMapping("/roadnet/baseMap")
public class baseMapController extends BaseController {

    private String prefix = "roadnet/baseMap";

    @Autowired
    private IBaseRoadwaysectionService baseRoadwaysectionService;

    /**
     * 路线查询界面
     * @return
     */
    @RequiresPermissions("roadnet:baseMapRoad:view")
    @GetMapping()
    public String baseBridge()
    {
        return prefix + "/roadMap";
    }

    /**
     * 获取道路路段信息
     */
    @GetMapping("/roadwaysection/{id}")
    @ResponseBody
    public TableDataInfo sectionlist(@PathVariable("id") String id)
    {
        List<BaseRoadwaysection> list = baseRoadwaysectionService.selectBaseRoadwaysectionListByRoadCode(id);
        for (BaseRoadwaysection item:list ) {
            String shape = item.getShape();
            Integer start = shape.indexOf('(');
            Integer end = shape.indexOf(')');
            String[] shapeOld = shape.substring(start + 1, end - 1 - start).split(",");
            Integer i=0;
            Integer length = shapeOld.length;
            String[] result = shapeOld[length / 2].split(" ");
            item.setX(Double.valueOf(result[2]));
            item.setY(Double.valueOf(result[1]));
        }
        return getDataTable(list);
    }

}
